<?php 
/**
 * @package Joomla
 * @subpackage Jcampaignmonitor
 * @copyright (C) 2010 - Matthieu BARBE - www.ccomca.com
 * @license GNU/GPL v2
 * 
 * Jcampaignmonitor is a derivative work of the excellent Campaign Monitor Module (from Van Eldijk Studios) and CampaignMonitor Ajax subscription Module (from Joomailer)
 * see http://www.vaneldijk.nl/ and http://www.joomailer.com/ for more information
 *
 * Jcampaignmonitor uses :
 * CampaignMonitorLib (CMBase.php => http://code.google.com/p/campaignmonitor-php/)
 * json class by Michal Migurski, Matt Knapp, Brett Stimmerman
 * 1 000 free "Farm Fresh Web Icons" => http://www.fatcow.com/free-icons/
 * extendedlistnamevalue.php & extendedlist.js are inspired by RocketTheme !
 *
 * Jcampaignmonitor is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

defined( '_JEXEC' ) or die( 'Restricted access' ); 

$uri =& JURI::getInstance(); 

// load mootools framework
JHTML::_('behavior.formvalidation');
$doc = &JFactory::getDocument();
$doc->addStyleSheet( 'modules/mod_jcampaignmonitor/assets/css/jcampaignmonitor.css' );

if( $params->get( 'required_name', 0 ) != 1 ) $error = "ERROR FORM"; else $error = "ERROR FORM2";

$doc->addScriptDeclaration("
function ValidateNewsletter(f) {
        if (document.formvalidator.isValid(f)) {
		var name  = $('formjcampaignmonitor').toQueryString();
		window.addEvent('domready', function(){										 	
		$(\"messagejcm\").removeClass(\"alert\").setHTML(\"<img src='".JURI::root()."modules/mod_jcampaignmonitor/assets/images/ajax-loader.gif' align='absmiddle' /> ".JText::_( 'LOADING' )."\");
		var url = '".JURI::root()."modules/mod_jcampaignmonitor/ajax-subscribe.php?' + name;
    
    	new Ajax(url, {
        method: 'get',
        onRequest: function () {
			$(\"jcm-send\").removeClass(\"showjcm\").addClass(\"hidejcm\");
		},
		onComplete: function( response ){
 		var resp = Json.evaluate( response );
		if (resp.success == 'false')
			{
				$(\"jcm-send\").removeClass(\"hidejcm\").addClass(\"showjcm\");
				$(\"messagejcm\").addClass(\"alert\").setHTML(resp.msg);
				
			}
			else
			{
				$(\"messagejcm\").removeClass(\"alert\").addClass(\"approved\").setHTML(\"".JText::_( 'SUBSCRIPTION SUCCESS' )."\");
				
			}
 
       }
                

    }).request();

}); 



            return false; 
        }
        else {
               
				$(\"messagejcm\").addClass(\"alert\").setHTML(\"".JText::_( $error )."\");
				
        }
        return false;
}





");


?>



<form action="<?php echo $uri->toString( array( 'scheme', 'host', 'port', 'path', 'query' ) ); ?>" method="post" id="formjcampaignmonitor"  autocomplete="off" class="form-validate" onsubmit="return ValidateNewsletter(this);">
 
   <?php if( $params->get( 'pretext' ) != "" ) : ?>
  <div class="jcm-pretext"><?php echo $params->get( 'pretext' ); ?></div>
  <?php endif; ?>
  <?php if( $params->get( 'display_name', 0 ) != 1 ) : ?>
  <label for="jcm-name"><?php echo JText::_( 'YOUR NAME' ); ?> :<br />
  </label>
  <input name="jcm-name" type="text" id="jcm-name" value="" size="20" <?php if( $params->get( 'required_name', 0 ) != 1 ) : ?>class="required"  <?php endif; ?>/>
  <br />
  <br />
   <?php endif; ?>
  <label for="jcm-mail"><?php echo JText::_( 'YOUR EMAIL' ); ?> :<br />
  </label>
  <input  name="jcm-mail" type="text" id="jcm-mail" value="" size="20" class="required validate-email"/>
  <br />
  <br />
  
  <?php if ($params->get( 'jcampaignmonitor_extendedlist_value_2' ) == "") : ?>
  <input type="hidden"  name="jcm-list" id="jcm-list" value="1" />
  <?php else : ?>
  <label for="jcm-list"><?php echo JText::_( 'YOUR LIST' ); ?> :<br />
  </label>
  <select name="jcm-list" id="jcm-list" class="inputbox" size="1" class="required" >
  <option value="" >- <?php echo JText::_( 'SELECT LIST' ); ?> -</option>
  <?php 
  	$i = 1;
	while ($params->get( 'jcampaignmonitor_extendedlist_value_'.$i ) != "") {
	echo "<option value=\"".$i."\" >".$params->get( 'jcampaignmonitor_extendedlist_name_'.$i )."</option>";
	
	$i++;
	}
	?>
   </select>
    
    <?php endif; ?>
  
  
  <div id="messagejcm"></div>
  <br />
  <?php echo JHTML::_( 'form.token' ); ?>
  <input type="hidden"  name="id" id="id" value="<?php echo $module->id; ?>" />
  <div align="center" id="jcm-send">
    <input type="submit" name="submit" id="start" value="<?php echo JText::_( 'SUBSCRIBE' ); ?>" class="jcm-submit" />
  </div>
  
   <?php if( $params->get( 'posttext' ) != "" ) : ?>
  <div class="jcm-posttext"><?php echo $params->get( 'posttext' ); ?></div>
  <?php endif; ?>

</form>

